home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / DubSource.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-20  |  2.6 KB  |  83 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Copyright (C) 1998-2001 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #ifndef f_DUBSOURCE_H
  19. #define f_DUBSOURCE_H
  20.  
  21. #include <windows.h>
  22. #include <vfw.h>
  23.  
  24. class InputFile;
  25.  
  26. class DubSource {
  27. private:
  28.     void *    format;
  29.     int        format_len;
  30.  
  31. protected:
  32.     void *allocFormat(int format_len);
  33.     virtual BOOL _isKey(LONG lSample);
  34.  
  35. public:
  36.     LONG lSampleFirst, lSampleLast;
  37.     AVISTREAMINFO    streamInfo;
  38.  
  39.     DubSource();
  40.     virtual ~DubSource();
  41.  
  42.     virtual BOOL init();
  43.     int read(LONG lStart, LONG lCount, LPVOID lpBuffer, LONG cbBuffer, LONG *lBytesRead, LONG *lSamplesRead);
  44.     virtual int _read(LONG lStart, LONG lCount, LPVOID lpBuffer, LONG cbBuffer, LONG *lBytesRead, LONG *lSamplesRead) = 0;
  45.  
  46.     void *getFormat() const { return format; }
  47.     int getFormatLen() const { return format_len; }
  48.  
  49.     virtual bool isStreaming();
  50.  
  51.     BOOL isKey(LONG lSample);
  52.     virtual LONG nearestKey(LONG lSample);
  53.     virtual LONG prevKey(LONG lSample);
  54.     virtual LONG nextKey(LONG lSample);
  55.  
  56.     virtual void streamBegin( bool fRealTime);
  57.     virtual void streamEnd();
  58.  
  59.     LONG msToSamples(LONG lMs) const {
  60.         return (LONG)(((__int64)lMs * streamInfo.dwRate + (__int64)500 * streamInfo.dwScale) / ((__int64)1000 * streamInfo.dwScale));
  61.     }
  62.     LONG samplesToMs(LONG lSamples) const {
  63.         return (LONG)(
  64.                 (((__int64)lSamples * streamInfo.dwScale) * 1000 + streamInfo.dwRate/2) / streamInfo.dwRate
  65.             );
  66.     }
  67.  
  68.     // This is more accurate than AVIStreamSampleToSample(), which does a conversion to
  69.     // milliseconds and back.
  70.  
  71.     static LONG samplesToSamples(const AVISTREAMINFO *dest, const AVISTREAMINFO *source, LONG lSamples) {
  72.         __int64 divisor = (__int64)source->dwRate * dest->dwScale;
  73.  
  74.         return (LONG)((((__int64)lSamples * source->dwScale) * dest->dwRate + divisor/2)
  75.                 / divisor);
  76.     }
  77.  
  78.     LONG samplesToSamples(const DubSource *source, LONG lSamples) const {
  79.         return samplesToSamples(&streamInfo, &source->streamInfo, lSamples);
  80.     }
  81. };
  82.  
  83. #endif